//
//  DetailView.m
//  豆瓣_精简版
//
//  Created by dllo on 15/11/7.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "DetailView.h"
#import "UIImageView+WebCache.h"
@implementation DetailView

- (void)dealloc
{
    [_plot_simple release];
    [_title release];
    [_genres release];
    [_country release];
    [_runtime release];
    [_poster release];
    [_rating_count release];
    [_rating release];
    [_release_date release];
    [_actors release];
    [super dealloc];
}

-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        [self creatSubview];
    }
    return self;
}

-(void)creatSubview{
    
    self.poster = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 110, 150)];
    [self addSubview:self.poster];
    
    UILabel *label1 = [[UILabel alloc]initWithFrame:CGRectMake(130, 15, 50, 20)];
    label1.text = @"评分:";
    [self addSubview:label1];
    
    self.rating = [[UILabel alloc]initWithFrame:CGRectMake(180, 15, 60, 20)];
    [self addSubview:self.rating];
    
    self.rating_count = [[UILabel alloc]initWithFrame:CGRectMake(250, 15, 120, 20)];
    [self addSubview:self.rating_count];
    
    self.release_date = [[UILabel alloc]initWithFrame:CGRectMake(130, 45, 120, 20)];
    [self addSubview:self.release_date];
    
    self.runtime = [[UILabel alloc]initWithFrame:CGRectMake(130, 75, 120, 20)];
    [self addSubview:self.runtime];
    
    self.genres = [[UILabel alloc]initWithFrame:CGRectMake(130, 105, 120, 20)];
    [self addSubview:self.genres];
    
    self.country = [[UILabel alloc]initWithFrame:CGRectMake(130, 135, 120, 20)];
    [self addSubview:self.country];
    
    UILabel *label2 = [[UILabel alloc]initWithFrame:CGRectMake(10, 170, 100, 40)];
    label2.text = @"制作人";
    label2.font = [UIFont boldSystemFontOfSize:22];
    [self addSubview:label2];
    
    self.actors = [[UILabel alloc]initWithFrame:CGRectMake(10, 220, 340, 100)];
    self.actors.numberOfLines = 0;
    [self addSubview:self.actors];
    
    UILabel *label3 = [[UILabel alloc]initWithFrame:CGRectMake(10, 330, 100, 40)];
    label3.text = @"电影情节";
    label3.font = [UIFont boldSystemFontOfSize:22];
    [self addSubview:label3];
    
    self.plot_simple = [[UILabel alloc]initWithFrame:CGRectMake(10, 380, 340, 200)];
    self.plot_simple.numberOfLines = 0;
    [self addSubview:self.plot_simple];
}

-(void)setMovieDetail:(MovieDetail *)movieDetail{
    
    if (_movieDetail != movieDetail) {
        [_movieDetail release];
        _movieDetail = [movieDetail retain];
    }
    self.plot_simple.text = movieDetail.plot_simple;
    self.genres.text = movieDetail.genres;
    self.country.text = movieDetail.country;
    self.runtime.text = movieDetail.runtime;
    self.rating_count.text = [NSString stringWithFormat:@"(%@评论)",movieDetail.rating_count];
    self.rating.text = movieDetail.rating;
    self.release_date.text = movieDetail.release_date;
    self.actors.text = movieDetail.actors;
    
    NSURL *url = [NSURL URLWithString:movieDetail.poster];
    [self.poster sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeHoderImage.png"]];
}

#pragma mark - 计算内容高度第一步:封装方法
+ (CGFloat)heightForContent:(NSString *)content width:(NSInteger)kuan{
    
    
    CGSize size = CGSizeMake(kuan, 10000);
    NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont systemFontOfSize:15], NSFontAttributeName, nil];
    CGRect frame = [content boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:dic context:nil];
    return frame.size.height;
}








@end
